package com.atguigu.daijia.customer.controller;

import com.atguigu.daijia.common.annotations.LoginValidate;
import com.atguigu.daijia.common.result.Result;
import com.atguigu.daijia.common.util.AuthContextHolder;
import com.atguigu.daijia.customer.service.CustomerService;
import com.atguigu.daijia.model.form.customer.UpdateWxPhoneForm;
import com.atguigu.daijia.model.vo.customer.CustomerLoginVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import reactor.netty.http.server.HttpServerRequest;

@Slf4j
@Tag(name = "客户API接口管理")
@RestController
@RequestMapping("/customer")
@SuppressWarnings({"unchecked", "rawtypes"})
public class CustomerController {
    @Autowired
    private CustomerService customerService;

    /**
     * 小程序授权登录接口
     * @param code 小程序端通过微信登录接口获得的临时登录凭证
     * @return 包含登录结果的信息对象，成功时会包含用户相关信息
     */
    @Operation(summary = "小程序授权登录")
    @GetMapping("/login/{code}")
    public Result<String> wxLogin(@PathVariable String code){
        return Result.ok(customerService.wxLogin(code));
    }

    /**
     * 获取用户登录信息
     * @return 包含用户登录信息的Result对象，使用CustomerLoginVo作为数据载体
     */
    @Operation(summary = "获取用户登录信息")
    @GetMapping("/getCustomerLoginInfo")
    @LoginValidate
    public Result<CustomerLoginVo> getCustomerLoginInfo(){
        return Result.ok(customerService.getCustomerLoginInfo());
    }

    @Operation(summary = "更新用户微信手机号")
    @LoginValidate
    @PostMapping("/updateWxPhone")
    public Result updateWxPhone(@RequestBody UpdateWxPhoneForm updateWxPhoneForm) {
        return Result.ok(customerService.updateWxPhoneNumber(updateWxPhoneForm));
    }
}

